﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class MP_FieldSpecDtls : System.Web.UI.UserControl
    {
        private IFieldSpecDetailBLL detailBLL = new FieldSpecDetailBLL();

        private RadComboBox cmbPositionType, cmbClassNo;
        private object _dataItem = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            cmbPositionType = (RadComboBox)cbPositionType.FindControl("cbPositionType");
            cbPositionType.ListPositionTypeComboBox("1");

            cmbClassNo = (RadComboBox)cbClassNo.FindControl("cbClassNo");           

            if (DataItem != null)
            {
                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {
                    lblSeq.Text = DataBinder.Eval(DataItem, "Sequence").ToString();
                    cmbPositionType.SelectedValue = DataBinder.Eval(DataItem, "PositionTypes.Sequence").ToString();
                    cbClassNo.ListClassComboBox(cmbPositionType.SelectedValue);
                    cmbClassNo.SelectedValue = DataBinder.Eval(DataItem, "Classes.Sequence").ToString();
                    txtDuration.Text = DataBinder.Eval(DataItem, "Durations").ToString();
                    txtRemarks.Text = DataBinder.Eval(DataItem, "Remarks").ToString();
                }                   
                else
                    cbClassNo.ListClassComboBox("1");

                btnUpdate.Visible = !(DataItem is Telerik.Web.UI.GridInsertionObject);
                btnAddnew.Visible = (DataItem is Telerik.Web.UI.GridInsertionObject);
            }
        }

        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }

        protected void btnAddnew_Click(object sender, EventArgs e)
        {
            string a = Session["FieldSpecSeq"].ToString();
            string b = cmbPositionType.SelectedValue;
            string c = cmbClassNo.SelectedValue;
            string d = txtDuration.Text.Trim();
            string g = txtRemarks.Text.Trim();

            detailBLL.Insert(Session["FieldSpecSeq"].ToString()
                , cmbPositionType.SelectedValue
                , cmbClassNo.SelectedValue
                , txtDuration.Text.Trim()
                , txtRemarks.Text.Trim()
                , 1);
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            detailBLL.Update(Int32.Parse(lblSeq.Text.Trim())
                , Session["FieldSpecSeq"].ToString()
                , cmbPositionType.SelectedValue
                , cmbClassNo.SelectedValue
                , txtDuration.Text.Trim()
                , txtRemarks.Text.Trim()
                , 1);
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }
    }
}